﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
using IWMAG.Core.EnhancedProperties.Extensions;

namespace IWMAG.Core.EnhancedProperties.ChangeNotification
{
    public static class PropertyChangeNotificationExtensions 
    {
        public static IObservable<T> AsObservable<T>(this IPropertyContainer owner, PropertyBacker<T> backer)
        {
            Contract.Requires(owner != null);
            Contract.Requires(backer != null);

            return backer.GetOrCreatePropertyNodeList(owner);   
        }

        public static IDisposable Subscribe<T>(this IPropertyContainer owner,PropertyBacker<T> backer, Action<T> onNext)
        {
            Contract.Requires(onNext != null);
            return owner.AsObservable(backer).Subscribe(onNext);
        }

        public static IDisposable Subscribe<T>(this IPropertyContainer owner, PropertyBacker<T> backer, Action<T> onNext, Action onCompleted)
        {
            Contract.Requires(onNext != null);
            Contract.Requires(onCompleted != null);
            return owner.AsObservable(backer).Subscribe(onNext, onCompleted);
        }


     
    }

}
